//+------------------------------------------------------------------+
//|                                                       tttttt.mq5 |
//|                                  Copyright 2025, MetaQuotes Ltd. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2025, MetaQuotes Ltd."
#property link      "https://www.mql5.com"
#property version   "1.00"

// 定义宏常量方便修改参数
#define RSI_PERIOD 7
#define CCI_PERIOD 7
#define APPLIED_PRICE PRICE_CLOSE  // RSI应用的价格
#define CCI_APPLIED_PRICE PRICE_TYPICAL  // CCI应用的价格(经典价格)

//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
   // 获取当前图表品种和时间周期
   string symbol = Symbol();
   ENUM_TIMEFRAMES timeframe = Period();
   
   Print("当前品种: ", symbol, " 时间周期: ", EnumToString(timeframe));
   
   // 初始化句柄
   int rsi_handle = INVALID_HANDLE;
   int cci_handle = INVALID_HANDLE;
   
   // 获取RSI值
   double rsi_values[];
   ArraySetAsSeries(rsi_values, true);
   rsi_handle = iRSI(symbol, timeframe, RSI_PERIOD, APPLIED_PRICE);
   
   if(rsi_handle == INVALID_HANDLE)
     {
      Print("获取RSI句柄失败! 错误代码: ", GetLastError());
      return;
     }
     
   if(CopyBuffer(rsi_handle, 0, 0, 3, rsi_values) <= 0)
     {
      Print("复制RSI数据失败! 错误代码: ", GetLastError());
      IndicatorRelease(rsi_handle);
      return;
     }
   
   Print("RSI(7)值 - 当前K线(k0): ", rsi_values[0], 
         ", 前根K线(k1): ", rsi_values[1], 
         ", 前前根K线(k2): ", rsi_values[2]);
   
   // 获取CCI值
   double cci_values[];
   ArraySetAsSeries(cci_values, true);
   cci_handle = iCCI(symbol, timeframe, CCI_PERIOD, CCI_APPLIED_PRICE);
   
   if(cci_handle == INVALID_HANDLE)
     {
      Print("获取CCI句柄失败! 错误代码: ", GetLastError());
      IndicatorRelease(rsi_handle);
      return;
     }
     
   if(CopyBuffer(cci_handle, 0, 0, 3, cci_values) <= 0)
     {
      Print("复制CCI数据失败! 错误代码: ", GetLastError());
      IndicatorRelease(rsi_handle);
      IndicatorRelease(cci_handle);
      return;
     }
   
   Print("CCI(7)值 - 当前K线(k0): ", cci_values[0], 
         ", 前根K线(k1): ", cci_values[1], 
         ", 前前根K线(k2): ", cci_values[2]);
   
   // 释放指标句柄
   IndicatorRelease(rsi_handle);
   IndicatorRelease(cci_handle);
  }
//+------------------------------------------------------------------+